﻿using System;
using System.Configuration;
using System.Web.Security;
using System.Web.UI;
using UDS.Components;

namespace UDS.SubModule.UnitiveDocument
{
    /// <summary>
    /// Online 的摘要说明。
    /// </summary>
    public partial class OnlinePage : Page
    {
        protected override void OnLoad(EventArgs e)
        {
            CheckUpdate();
            base.OnLoad(e);
        }

        private void CheckUpdate()
        {
            /*
             * 1. 更新activetime 
             * 2. 判断sessionid 
             * 3. 删除十分钟内未活动人 
             * 4. 拿到最新在线人数
             */
            var checkUpdateResult = UDS.WebApp.OnlineService.CheckUpdateInternal(Context);
            lblOnlineCount.Text = checkUpdateResult.NumOnlineUsers.ToString();
            if (checkUpdateResult.NumOnlineUsers == -1)
            {
                if (!UDSConfig.AllowMultipleLogon)
                {
                    SiteContext.Current.AlertAndRedirect("有相同用户登陆或同一机器两用户登陆,窗口将自动关闭!", ResolveUrl("~/SubModule/Login/Index.aspx"));
                }
            }
            else
            {
                if (checkUpdateResult.HasNewMessage) //incoming a new msg
                {
                    var remindTypeCookie = Request.Cookies["UDS_RemindType"];
                    if (remindTypeCookie != null)
                    {
                        if (remindTypeCookie.Value == "1")
                        {
                            lit.Text = "<script language=javascript> mytop=screen.availHeight-310;myleft=0;var newmsgwin=window.open('../SM/MsgManage.aspx','auto_call_show','height=230,width=400,status=0,toolbar=no,menubar=no,location=no,scrollbars=yes,top='+mytop+',left='+myleft+',resizable=yes');newmsgwin.focus();</script>";
                        }
                        else
                        {
                            lit.Text = "<a href='#' onclick='show_sm()'><img src='../../Images/smsremind.gif' border=0></a>";
                        }
                    }
                    else
                    {
                        lit.Text = "<script language=javascript> mytop=screen.availHeight-310;myleft=0;var newmsgwin=window.open('../SM/MsgManage.aspx','auto_call_show','height=230,width=400,status=0,toolbar=no,menubar=no,location=no,scrollbars=yes,top='+mytop+',left='+myleft+',resizable=yes');newmsgwin.focus();</script>";
                    }
                }
            }
        }
    }
}
